package com.tuomaxu.utils;

import java.nio.charset.StandardCharsets;

public class HttpProtocolUtil {
    public  static String getHttp200(String content){
        int length = content.getBytes(StandardCharsets.UTF_8).length;
        String str = getHttpHeader200(length) +content;
        return str;
    }

    public  static String getHttpHeader200(int length){
        String str = "HTTP/1.1 200 OK \n"
                +"Content-Type: text/html;charset=utf-8 \n"
                +"Content-Length: "+length+"\n"
                +"\r\n";
        return str;
    }

    public  static String getHttp404(){
        String content = "404 Not Found";
        String str = "HTTP/1.1 404 NOT Found \n"
                +"Content-Type: text/html;charset=utf-8 \n"
                +"Content-Length: "+content.getBytes(StandardCharsets.UTF_8).length+"\n"
                +"\r\n"
                +content;
        return str;
    }
}
